$(document).ready(function () {
  // 点击“随机产生20个整数”按钮事件
  $('#generateButton').click(function () {
    let numbers = [];
    for (let i = 0; i < 20; i++) {
      let randomNum = Math.floor(Math.random() * 9000 + 1000);
      numbers.push(randomNum);
    }
    numbers.sort((a, b) => a - b);
    let result = "随机产生20个4位整数，分别如下：\n" + numbers.join(', ') + "\n从小到大排序后结果为：\n" + numbers.join(', ');
    $('#resultTextarea').val(result);
  });

  // 点击“找出能被5整除的整数”按钮事件
  $('#findButton').click(function () {
    let textareaValue = $('#resultTextarea').val();
    let numbers = textareaValue.split(',').map(Number).filter(num =>!isNaN(num));
    let divisibleByFive = numbers.filter(num => num % 5 === 0);
    let result = $('#resultTextarea').val() + "\n能被5整除的整数有：\n" + divisibleByFive.join(', ');
    $('#resultTextarea').val(result);
  });

  // 点击“重置”按钮事件
  $('#resetButton').click(function () {
    $('#resultTextarea').val('');
  });
});